package com.cjq.invite.controller;

import com.cjq.common.domain.Firm;
import com.cjq.common.domain.Invite;
import com.cjq.common.domain.request.InviteReq;
import com.cjq.common.domain.response.InviteRes;
import com.cjq.common.result.PageResult;
import com.cjq.common.result.Result;
import com.cjq.invite.service.InviteService;
import com.cjq.invite.util.OssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/invite")
public class InviteController {
    @Autowired
    private InviteService inviteService;
    @Autowired
    private OssUtil ossUtil;

    /**
     * 列表查询
     * @param inviteReq
     * @return
     */
    @PostMapping("/inviteList")
    public Result<PageResult<InviteRes>> inviteList(@RequestBody InviteReq inviteReq){
        return inviteService.inviteList(inviteReq);
    }

    /**
     * 企业下拉框
     * @return
     */
    @GetMapping("/firmList")
    public Result<List<Firm>> firmList(){
        return inviteService.firmList();
    }

    /**
     * 添加
     * @param invite
     * @return
     */
    @PostMapping("/insert")
    public void insert(@RequestBody Invite invite){
        inviteService.insert(invite);
    }

    /**
     * 修改
     * @param invite
     */
    @PutMapping("/update")
    public void update(@RequestBody Invite invite){
        inviteService.update(invite);
    }

    /**
     * 单删
     * @param inviteId
     */
    @DeleteMapping("/delete/{inviteId}")
    public void delete(@PathVariable String inviteId){
        inviteService.delete(inviteId);
    }



    /**
     * OSS图片上传
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result<String> upload(@RequestParam MultipartFile file){
        String filePath = OssUtil.uploadMultipartFile(file);
        return Result.success(filePath);
    }
}
